<?php

#################################################################
#								HTML
#################################################################

/**
 * Login form registed as 'form/login'
 * $vars['email']
 * $vars['pass']				
 * $vars['display_login_form']	//Boolean
 * 
 */

if($_CONTEXT=='HTML'){
	
	if($user_logged!==FALSE){
		$_CSS_STACK->push(blg_get_site_url().'form/login.css', TRUE);
		$_JS_STACK->push(blg_get_site_url().'form/login.js', TRUE);		
		
		$user_logged= blg_get_logged_in_user_guid();	
		
		if(!is_bool($vars['display_login_form']))
			$vars['display_login_form']= FALSE;
	
		//BUILD INPUTS: Email & Password
		$input_email= blg_view('element/input', array(
			'name' 	=> 'email',
			'description' 	=> blg_echo('email'),
			'id' 	=> 'header_input_login_email',
			'value'	=> $vars['email'],
			'width' => 130
		));
		
		$input_pass= blg_view('element/input', array(
			'name' 	=> 'pass',
			'password'	=> TRUE,
			'description' 	=> blg_echo('password'),
			'id' 	=> 'header_input_login_password',
			'value'	=> $vars['pass'],
			'width' => 130
		));
		
		// PASSWORD FORGOTTEN
		$password_forgotten= '<a class="header_password_forgotten" href="'.blg_get_site_url().'user/password/forgotten?'.blg_security_url().'">'.blg_echo('forms:password:reset:title').'</a>';
		
		//BUILD BUTTONS: Enter & Cancel
		$button_submit= blg_view('element/button', array(
			'text' => blg_echo('enter'),
			'submit' => TRUE,
			'precall' => 'v_header_login_form(true)'	
		));
	
		$button_submit_cancel= blg_view('element/button', array(
			'text' => blg_echo('cancel'),	
			'action' => "blg_header_login_hide()",	
			'color' => 'grey'
		));
		
		//SECURITY TOKENS
		$security= blg_security_input();		

		//BUILD FORM
		$content= '
			<div class="blg_header_login_form_div">'.$input_email.'</div>
			<div class="blg_header_login_form_div">'.$input_pass.'</div>
			<div class="blg_header_login_form_div">'.$password_forgotten.'</div>
			<div class="blg_header_login_form_div">'.$button_submit.' '.$button_submit_cancel.'</div>	
			'.$security.'
		';
	
		$form= blg_view('element/form', array(
			'action' 			=> blg_get_site_url().'action/user/login',
			'id'				=> 'blg_header_login_form_id',
			'name'				=> 'blg_header_login_form',
			'submit_callback'	=> 'return v_header_login_form(false);',
			'content'			=> $content		 
		));
		
		//BUILD LOGIN DIV
		$login_div= '
		<div id="blg_header_login_form_div" class="blg_component_header_login_form">
			'.$form.'
		</div>
		';	
		
		echo $login_div;
		
		//JS CODE
		if($vars['display_login_form']===TRUE || blg_session_get('display_login_form')){
			$code="blg_header_login_show();";
			
			$_JS_CODE->append($code, ON_DOC_READY);
		}
	}
}
#################################################################
#								JS
#################################################################
elseif($_CONTEXT=='JS'){ ?>

function blg_header_login_show(){
	blg_form_register_hide();
	$('#blg_header_login_form_div').fadeIn(400);
}

function blg_header_login_hide(){
	$('#blg_header_login_form_div').fadeOut(150);
}

function v_header_login_form(print_errors){
	error= false;
	
	if(!v_is_email($('#header_input_login_email').val())){
		if(print_errors)
			blg_error('<?php echo blg_echo('error:email:invalid')?>');
		error= true;
	}
	
	pass= $('#header_input_login_password').val();	
	if(pass.length < 1){
		if(print_errors)
			blg_error('<?php echo blg_echo('error:password:empty')?>');
		error= true;
	}	
		
	return (!error);
}

<?php }
#################################################################
#								CSS
#################################################################
elseif($_CONTEXT=='CSS'){ ?>

div.blg_component_header_login_form{
	position: absolute;
	top: 82px;
	right: 5px;
	
	display: none;
	
	background-color: <?php echo blg_color('grey','B')?>;
	padding: 5px 10px 2px 10px;
	
	border-radius: 12px;
}

div.blg_component_header_login_form div.blg_header_login_form_div{
	margin: 5px 0;
	text-align: center;
}

div.blg_component_header_login_form div.blg_header_login_form_div a{
	font-size: 10px;
	color: #333333 !important;
}
div.blg_component_header_login_form div.blg_header_login_form_div a:hover{
	text-decoration: underline;
}

<?php }
		